package com.geek.javase.ch11.work.streamwork;

/*
 *@author wangpeng
 *2025/10/22 18:57
 *@description TODO
 */
//1.将英文字符串的数组中的元素全部变为大写，以集合输出。将整数的数组中的元素全部加3，以集合输出。

//2.统计员工人数、平均工资、工资总额、最高工资、统计工资的所有信息。
//counting() 、averagingDouble()、maxBy()、summingInt()、summarizingDouble()

//3.将员工按薪资是否高于8000分为两部分；将员工按性别分组；将员工按性别和地区分组。
//partitioningBy()、groupingBy()

//4.将所有员工的名称用逗号拼接
//joining()

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo2 {
    public static void main(String[] args) {

        //1.将英文字符串的数组中的元素全部变为大写，以集合输出。将整数的数组中的元素全部加3，以集合输出。
        List<String> list1 = Stream.of("tomorrow","will","be","better").map(s->s.toUpperCase()).collect(Collectors.toList());
        System.out.println("list1: " + list1);
        List<Integer> list2 = Stream.of(1,2,3,4,5).map(i->i+3).collect(Collectors.toList());
        System.out.println("list2: " + list2);

        //2.统计员工人数、平均工资、工资总额、最高工资、统计工资的所有信息。
        //counting() 、averagingDouble()、maxBy()、summingInt()、summarizingDouble()
        Employee[] employees = {new Employee("liyi",20,8000.0),
                    new Employee("wanger",26,9000.0),
                    new Employee("zhangsan",18,7000.0),
                    new Employee("zhaosi",22,9900.0),
                    new Employee("wangwu",23,10000.0),};
        Long count = Stream.of(employees).collect(Collectors.counting());
        System.out.println("员工人数: " + count);
        Double averageSalsry = Stream.of(employees).collect(Collectors.averagingDouble(Employee::getSalary));
        System.out.println("平均工资: " + averageSalsry);
        Double totalSalary = Stream.of(employees).collect(Collectors.summingDouble(Employee::getSalary));
        System.out.println("工资总额: " + totalSalary);
        Optional maxSalary = Stream.of(employees).collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary)));
        System.out.println("最高工资: " + maxSalary);
        DoubleSummaryStatistics summaryStatistics = Stream.of(employees).collect(Collectors.summarizingDouble(Employee::getSalary));
        System.out.println("工资统计信息: " + summaryStatistics);

        //3.将员工按薪资是否高于8000分为两部分
        Map<Boolean,List<Employee>> partEmployee = Stream.of(employees).collect(Collectors.partitioningBy(e->e.getSalary()>8000));
        System.out.println("薪资高于8000的员工：" + partEmployee.get(true));
        System.out.println("薪资低于8000的员工：" + partEmployee.get(false));
        //4.将所有员工的名称用逗号拼接
        String joinName = Stream.of(employees).map(Employee::getName).collect(Collectors.joining(","));
        System.out.println("将所有员工的名称用逗号拼接: " + joinName);

    }
}
